﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    private int id = Helper.getQuery("cid");
    private string url = Helper.getQuerystr("url");
    PanelBusiness pb = new PanelBusiness();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (url != null && !url.Equals(""))
        {
           // this.thongtinchung.Controls.Clear();
            PanelControl pc = (PanelControl)LoadControl(url);
            pc._id = Helper.getQuery("pid");
            pc.ViewStateMode = System.Web.UI.ViewStateMode.Disabled;
            this.thongtinchung.Controls.Add(pc); 
        }
        else if (id == 0 )
        {
            id = 1;
        }

        bool display_all = false;
        bool cell1 = false, cell2 = false, cell3 = false, cell4 = false, cell5 = false,
            cell6 = false, cell7 = false, cell8 = false, cell9 = false, cell10 = false,cell11=false,cell12=false,cell13=false;
        SqlDataReader readAll = pb.getDisplayAll();
        if (readAll.HasRows)
        {
            while (readAll.Read())
            {
                PanelControl pc = (PanelControl)LoadControl("Panel.ascx");
                pc._id =int.Parse(readAll["panelID"].ToString());
                switch (int.Parse(readAll["cellID"].ToString()))
                {
                    case 1:

                        break;
                    case 2:
                        this.menuTop.Controls.Add(pc);
                        cell2 = true;
                        break;
                    case 11:
                        this.footer.Controls.Add(pc);
                        cell11 = true;
                        break;
                }
            }
        }

        ArrayList items = pb.getPanelByChanel(id);
        if (items != null)
        {
            PanelEntities item = (PanelEntities)items[0];
            for (int i = 0; i < items.Count; i++)
            {
                item = (PanelEntities)items[i];
                PanelControl pc = (PanelControl)LoadControl("Panel.ascx");                
                pc._id = item._panelID;                
                switch (item._cellID)
                {
                    case 1:
                        
                        break;
                    case 2:
                        if(!cell2)
                        this.menuTop.Controls.Add(pc);
                        break;
                    case 3:

                        break;
                    case 4:
                        if(!cell4 && (url==null ||url.Equals("")))
                        this.datchuyenbay.Controls.Add(pc);
                        break;
                    case 5:
                        if (!cell5 && (url == null || url.Equals("")))
                            this.thongbao.Controls.Add(pc);
                        break;
                    case 8:
                        if (!cell8 && (url == null || url.Equals("")))
                            this.diemden.Controls.Add(pc);
                        break;
                    case 9:
                        if (!cell9 && (url == null || url.Equals("")))
                        this.formdangnhap.Controls.Add(pc);
                        break;
                    case 11:
                        if(!cell11)
                        this.footer.Controls.Add(pc);
                        break;
                    case 12:
                        if (!cell12 && (url == null || url.Equals("")))
                        this.thongtinchung.Controls.Add(pc);
                        cell12 = true;
                        break;
                    case 13:
                        if (!cell13 && (url == null || url.Equals("")))
                            this.flightInfo.Controls.Add(pc);
                        break;
                }
            }
        }
        
         
    }
}
